/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.io.File;

import de.sql.toolkit.model.Column;
import de.sql.toolkit.model.Table;

/**
 * @author jkonopka
 * 
 */
public class JvModelToStringGenerator extends AbstractJvModelGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2775467435324808199L;

	/**
	 * @param dstPath
	 * @param table
	 */
	public JvModelToStringGenerator(File dstPath, Table table) {
		super(dstPath, table);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.writer.IWriter#write()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder content = new StringBuilder();
		content.append("\tpublic String toString() {\n");
		content.append("\t\tfinal StringBuilder sb = new StringBuilder();\n");
		content.append("\t\tsb.append(\"");
		content.append(getTable().getName());
		content.append(" [");
		for (final Column column : getTable().getColumns()) {
			content.append(prepareName(column.getName()));
			content.append("=\");\n");
			content.append("\t\tsb.append(");
			content.append(prepareName(column.getName()));
			content.append(");\n");
			content.append("\t\tsb.append(\", ");
		}
		content.delete(content.lastIndexOf("\t\tsb.append(\", "), content.length());
		content.append("\t\tsb.append(\"]\");\n");
		content.append("\t\treturn sb.toString();\n");
		content.append("\t}\n");
		return content.toString();
	}

}
